package com.xckj.cycling.activity

import android.content.Intent
import android.os.Bundle
import android.view.View
import com.junca.android.base.CViewBinding
import com.xckj.cycling.databinding.ActivitySuggesstionRouteBinding
import com.xckj.cycling.framework.BaseActivityKt
import com.xckj.cycling.utils.MapUtils
import com.xckj.cycling.utils.RouteUtils

class SuggestionRouteActivity : BaseActivityKt() {
    @CViewBinding
    lateinit var viewBinding: ActivitySuggesstionRouteBinding

    override fun initView(root: View, savedInstanceState: Bundle?) {
        super.initView(root, savedInstanceState)
        lifecycle.addObserver(viewBinding.maps)
        viewModel.routes.observe(this) { routes ->
            viewBinding.maps.drawRoute(routes)
            viewBinding.distanceDuratioon.text = routes.let { navigationRoutes ->
                val d = MapUtils.getTotalDistance(navigationRoutes)
                viewBinding.distance.text = RouteUtils.getDistance(d.distance)
                val text =
                    "${RouteUtils.getDistance(d.distance)}/ ${RouteUtils.getDuration(d.duration)}"
                text
            }
            viewBinding.startRide.setOnClickListener {
                startActivity(Intent(this, NavigationActivity::class.java))
                finish()
            }
        }
    }
}